//
//  InviteCodeView.swift
//  Order
//
//  Created by Lazyloading on 2020/8/3.
//  Copyright © 2020 lazyloading. All rights reserved.
//

import UIKit
import PKHUD
import QMUIKit

class InviteCodeView: UIView {

    var copyBlock : ((UIButton) -> ())?
    
    let titleLabel : UILabel = {
        let label = UILabel.init();
        label.textColor = ZMColor.Black.black1;
        label.textAlignment = .center;
        label.font = UIFont.init(fontType: .medium, fontSize: 16);
        label.text = "邀请码";
        return label;
    }();
    
    let inviteCodeLabel : QMUILabel = {
        let label = QMUILabel.init();
        label.textColor = ZMColor.Black.black3;
        label.textAlignment = .center;
        label.font = UIFont.init(fontType: .medium, fontSize: 24);
        label.backgroundColor = ZMColor.Gray.gray1;
        label.layer.cornerRadius = 5;
        label.layer.masksToBounds = true;
        label.text = "天王盖地虎";
        
        return label;
    }();
    
    let copyBtn : UIButton = {
        let btn = UIButton.init();
        btn.setTitle("复制到剪切板", for: .normal);
        btn.setTitleColor(.white, for: .normal);
        btn.backgroundColor = ZMColor.Orange.orange1;
        btn.titleLabel?.font = UIFont.init(fontType: .regular, fontSize: 16);
        btn.addTarget(self, action: #selector(copyActiion(sender:)), for: .touchUpInside);
        btn.layer.cornerRadius = 10;
        btn.layer.masksToBounds = true;
        return btn;
    }();
    
    
    override init(frame: CGRect) {
        super.init(frame: frame);
        
        self.loadDefaultSetting();
        self.initSubViews();
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func copyActiion(sender : UIButton){
        if self.copyBlock != nil {
            self.copyBlock!(sender);
        }
        let copy = UIPasteboard.general;
        copy.string = self.inviteCodeLabel.text;
        HUD.flash(.label("复制成功"), delay: 1);
    }
    
    //    MARK: 🐷 加载默认设置 🐷
    private  func loadDefaultSetting()  {
        
    }
    //    MARK: 🐷 初始化子视图 🐷
    private  func initSubViews()  {
        self.addSubview(self.titleLabel);
        self.addSubview(self.inviteCodeLabel);
        self.addSubview(self.copyBtn);
        
        self.layout();
        
    }
    
    func layout() {
        
        self.titleLabel.snp.makeConstraints { (make) in
            make.leading.equalToSuperview().offset(15);
            make.trailing.equalToSuperview().offset(-15);
            make.top.equalToSuperview().offset(10);
        }
        
        self.inviteCodeLabel.snp.makeConstraints { (make) in
            make.leading.trailing.equalTo(self.titleLabel);
            make.top.equalTo(self.titleLabel.snp.bottom).offset(20);
            make.height.equalTo(40)
        };
        
        self.copyBtn.snp.makeConstraints { (make) in
            make.leading.trailing.equalTo(self.titleLabel);
            make.height.equalTo(50);
            make.top.equalTo(self.inviteCodeLabel.snp.bottom).offset(20);
        }
        
        
        
        
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
    }

}
